﻿using System;
using System.Diagnostics;

namespace BMServiceGenerator
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            try
            {
                Arguments arguments = new ArgumentsParser().Parse(args);

                if (arguments != null)
                {
                    FolderFileManager.SetupOutputFolder(arguments);

                    arguments.TempFolder = FolderFileManager.SetupTempFolder(arguments);

                    var serviceCreator = new ServiceCreator(arguments);
                    serviceCreator.TransformModel();

                    FolderFileManager.DeployToOutput(arguments);
                    Console.WriteLine(string.Format("Service generated and succesfully compiled to {0}",
                                                    arguments.OutputFolder));
                }
            }
            catch (Exception exception)
            {
                EventLog.WriteEntry("BAM Servive Gen", exception.Message + "\n\n" + exception.StackTrace,
                                    EventLogEntryType.Error);

                Console.WriteLine(exception.Message);
                Console.WriteLine("An exception occured. See event log for further details");
            }
        }
    }
}